Skip to content

Deferred: Deprecate deferred.pipe() method #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

dmethvin
Copy link
Member

Ref #89

jQuery.Deferred = function() {
var deferred = oldDeferred.apply( this, arguments );

deferred.pipe = function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this will add the pipe method to the deferred, but not to the promise - using .then or .promise would yield a promise that does not have a pipe method unless I'm mistaken.

In order to get the method available everywhere it needs to be, this probably needs to look like

function pipe() { ... }

deferred.pipe = deferred.promise().pipe = pipe;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I totally missed that case! I need to go back and double check some of the edge cases since for example a Deferred can have a different object applied as its prototypical promise object and none of that is being covered here.

@dmethvin
Copy link
Member Author

I still feel like I'm missing some cases here, although it doesn't need to be bulletproof. @gibson042 what do you think?

jQuery.Deferred = function() {
var deferred = oldDeferred.apply( this, arguments );

// Don't add this method if the current jQuery doesn't provide it

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean "only add this method if the current jQuery doesn't provide it"

Edit: Wait, I think I'm confused....shouldn't migrate be adding it always for back-compat in addition to overriding it for the warn?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overriding it for the warning. I didn't want to add .pipe if, for example, they were using jQuery 1.5 because .pipe wasn't there and maybe they're doing a feature detect or something. I suppose I could always add it but it seemed better to NOT shim it if the original Deferred didn't have it.

But talking to the rubber ducky now I realize that I'm not correctly covering the version 1.6 to 1.8 region where we had .then but it didn't return a new promise. In those cases we should use the existing .pipe which does return a new promise.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was confusing myself; I was making the false assumption that .pipe was being removed in 3.0, but I realize that isn't the case. What you said about older versions is def true though

@jaubourg
Copy link
Member

You're probably safer with something like this:

var Deferred = jQuery.Deferred;

jQuery.Deferred = function( func ) {
    var deferred = Deferred();
    var pipe = deferred.pipe;
    if ( pipe ) {
        deferred.pipe = deferred.promise().pipe = function() {
            migrateWarn( "deferred.pipe() is deprecated" );
            return pipe.apply( this, arguments );
        };
    }
    if ( func ) {
        func.call( deferred, deferred );
    }
    return deferred;
};

@dmethvin
Copy link
Member Author

Thanks @jaubourg! It makes sense to wait until we've shimmed the .pipe() to call the function if it was provided, I didn't catch that case.

@gibson042
Copy link
Member

I like @jaubourg's code and would take it even farther, dropping the if ( pipe ) in favor of an unconditional definition in accord with the single-minded purpose I've advocated elsewhere ("restore backwards incompatibilities introduced between jQuery 1.11.2 and 3.0.0").

By the way, should I make an issue/PR for that?

@dmethvin
Copy link
Member Author

I should be able to get to it in the next day or two. Thoughts on the unit tests?

@gibson042
Copy link
Member

Thoughts on the unit tests?

Hmmm, you'll need to be async because of then changes, but you'll also want to guarantee that pipe is synchronous. Also probably one showing that dfdRejected.pipe( null, function() { return 1; } ) yields a rejected Deferred (another then/pipe distinction). Other than that, LGTM.

@dmethvin
Copy link
Member Author

Seems like now would be a good time to upgrade QUnit as well then. Let the yak shaving begin!

@dmethvin
Copy link
Member Author

dmethvin commented Apr 6, 2015

Closed in favor of #101

@mgol
Copy link
Member

mgol commented Jul 28, 2015

Closed in favor of #101

It still hasn't been closed. :) I'm closing it then.

@mgol mgol closed this Aug 3, 2015
@dmethvin dmethvin deleted the deprecate-pipe branch November 21, 2015 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants